<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of factura
 *
 * @author jorge-luis
 */
class factura extends CI_Model {

    public $total;
    public $subtotal;
    public $tarifaIva;
    public $suman;
    public $fecha;
    public $numero;
    public $descuento;
    public $paciente_id;
    public $estado;

    function __construct() {
        parent::__construct();
    }

    function grabar($datos) {
        $this->db->insert('factura', $datos);
        return $this->db->insert_id();
    }

    function numero() {
        $this->db->select_max('numero');
        $this->db->from('factura f');
        $lista = $this->db->get();
        if ($lista->num_rows() > 0) {
            return $lista->result_array();
        } else {
            return null;
        }
    }

    function modificar($id) {
        $this->db->select('*');
        $this->db->from('factura');
        $this->db->where('id', $id);
        $lista = $this->db->get();
        if ($lista->num_rows() > 0) {
            return $lista->row_array();
        } else {
            return null;
        }
    }

    function buscar($filtro) {
        $this->db->select('f.*,p.nombres,p.apellidos');
        $this->db->from('factura f');
        $this->db->join('paciente as p', 'f.paciente_id = p.id');
        $this->db->like('numero', $filtro);
        $this->db->like('p.nombres', $filtro);
        $this->db->or_like('p.apellidos', $filtro);
        $this->db->or_like('p.numero_identificacion', $filtro);
        $lista = $this->db->get();
        if ($lista->num_rows() > 0) {
            return $lista->result_array();
        } else {
            return null;
        }
    }

}
